import java.io.IOException;
import java.lang.reflect.InvocationTargetException;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

import Game.GameHelper;
import Screens.Manager.ScreenManager;
import Screens.MyScreens.DeadScreen;
import Screens.MyScreens.GameScreen;
import Screens.MyScreens.IntroScreen;
import Screens.MyScreens.MenuScreen;
import Tools.Configuration;

/** Application class
 * @author Aikidos
 */
public class Application extends BasicGame{

	public Application(String title) {
		super(title);
	}

	@Override
	public void render(GameContainer gc, Graphics g) throws SlickException {
		ScreenManager.draw(g);
	}

	@Override
	public void init(GameContainer gc) throws SlickException {
		
		// Initialize configurations
		try {
			Configuration.init();
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		
		// Initialize screen manager
		ScreenManager.initialize();
		ScreenManager.addScreen("IntroScreen", new IntroScreen());
		ScreenManager.addScreen("MenuScreen", new MenuScreen());
		ScreenManager.addScreen("GameScreen", new GameScreen());
		ScreenManager.addScreen("DeadScreen", new DeadScreen());
		try {
			ScreenManager.go("IntroScreen");
		} catch (InstantiationException | IllegalAccessException
				| IllegalArgumentException | InvocationTargetException
				| NoSuchMethodException | SecurityException
				| ClassNotFoundException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void update(GameContainer gc, int delta) throws SlickException {
		try {
			ScreenManager.update(delta);
		} catch (InstantiationException | IllegalAccessException
				| IllegalArgumentException | InvocationTargetException
				| NoSuchMethodException | SecurityException
				| ClassNotFoundException e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) throws SlickException {
		AppGameContainer app = new AppGameContainer(new Application(
				"Aeowin"));

		GameHelper.init(app);
		
		app.setIcon("res/gfx/icons/main.png");

		app.setDisplayMode(800, 600, false);
		app.setShowFPS(false);
		app.setVSync(true);
		app.start();
	}
}
